package net.yeah.mickey_zhouyou.database.util;

import java.lang.reflect.Field;
import java.util.Map.Entry;
import java.util.Set;

import junit.framework.Assert;

import org.junit.Test;

public class ClassFieldsCacheTest {

	@Test
	public void setgetValueTest() {
		A a = new A();

		ClassFieldsCache.setValue(a, "i", 123);
		ClassFieldsCache.setValue(a, "l", 234L);
		ClassFieldsCache.setValue(a, "s", "abc");

		int i = (Integer) ClassFieldsCache.getValue(a, "i");
		Long l = (Long) ClassFieldsCache.getValue(a, "l");
		String s = (String) ClassFieldsCache.getValue(a, "s");

		Assert.assertEquals(i, 123);
		Assert.assertEquals(l, Long.valueOf(234));
		Assert.assertEquals(s, "abc");
	}

	public static void main(String[] args) {
		Set<Entry<String, Field>> set = ClassFieldsCache.getAllFields(A.class);
		for (Entry<String, Field> e : set) {
			System.out.println(e.getKey() + ":"
					+ e.getValue().getType().getName());
		}
	}

	static class A {
		private int i;
		private Long l;
		private String s;
	}

}